unit uniManDespesa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uniManPadrao, DB, ADODB, Grids, DBGrids, StdCtrls, ExtCtrls,
  Buttons;

type
  TfrmManDespesa = class(TfrmManPadrao)
    procedure btnPesquisaClick(Sender: TObject);
    procedure btnIncluirClick(Sender: TObject);
    procedure btnEditarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    procedure p_Select(pParametros:String);
  public
    { Public declarations }
  end;

var
  frmManDespesa: TfrmManDespesa;

implementation

uses uniCadDespesa;

{$R *.dfm}

{ TfrmManDespesa }

procedure TfrmManDespesa.p_Select(pParametros: String);
var sSQL : String;
begin
  sSQL := 'SELECT * FROM TB_DESPESA WHERE 1=1';
  sSQL := sSQL + pParametros;
  QR_Grid.Close;
  QR_Grid.SQL.Clear;
  QR_Grid.SQL.Add(sSQL);
  QR_Grid.Open;


end;

procedure TfrmManDespesa.btnPesquisaClick(Sender: TObject);
  var sParametros : String;
begin
  inherited;
  if edtCodigo.Text <> '' then
    sParametros := sParametros + ' AND cd_despesa LIKE '+QuotedStr(edtCodigo.Text);

  if edtDescricao.Text <> '' then
    sParametros := sParametros + ' AND descricao LIKE '+QuotedStr(edtDescricao.Text);
  
  p_Select(sParametros);
end;

procedure TfrmManDespesa.btnIncluirClick(Sender: TObject);
begin
  inherited;
   try
    Application.CreateForm(TfrmCadDespesa, frmCadDespesa);
    frmCadDespesa.sEstado := 'I';
    frmCadDespesa.sCdCampo := '';
    frmCadDespesa.ShowModal;
  finally
     frmCadDespesa.Free;
  end;
  p_Select('');
end;

procedure TfrmManDespesa.btnEditarClick(Sender: TObject);
begin
  inherited;
  try
    Application.CreateForm(TfrmCadDespesa, frmCadDespesa);
    frmCadDespesa.sEstado := 'E';
    frmCadDespesa.sCdCampo := QR_Grid.FieldByName('cd_despesa').AsString;
    frmCadDespesa.ShowModal;
  finally
     frmCadDespesa.Free;
  end;
  p_Select('');

end;

procedure TfrmManDespesa.FormShow(Sender: TObject);
begin
  inherited;
  p_Select('');
end;

end.
